home *** CD-ROM | disk | FTP | other *** search
- >XXX0609 Total lines for the build status message calculation
- //--------------------------------------------------------------------
- //
- >001// Module: <JDPModule>
- >002// Description: <Class Description>
- //
- //--------------------------------------------------------------------
-
- import java.awt.*;
- import java.applet.*;
- import java.util.StringTokenizer;
- import java.util.Vector;
-
-
- >003public class <JDPUserBill> extends JDPClassLayout {
-
- JDPUser user;
- JDPJagg jaggSQL;
- JDPWhereClause jdpWhereClause;
- JDPSearchResults searchResults;
- JDPTextGrid tableContents;
-
- String[] psortChoice;
- String[] pdisplayChoice;
- int itemIndex;
- boolean insertRequested = false;
- boolean deleteRequested = false;
- String pfromWhereClause;
- String[][] rowKey;
- int keyCount;
- int prevColumnCount;
- >119 int columnCount = <columnCount>;
-
- //
- // Declare screen components
- //
- >004 <TextField username>;
-
-
- public void InitClass(JDPUser user, Panel targetPanel, String moduleParameter) {
-
- this.user = user;
- //
- // Set JAGG settings for this class
- //
- jaggSQL = new JDPJagg(user.jaggPath);
- jaggSQL.setNULL("space");
- >997 jaggSQL.setMRW("<maxRows>");
- >998 jaggSQL.setDSN("<datasource>");
- >999 jaggSQL.setCSTR("<connectstr>");
-
- setLayout(new BorderLayout());
- setFont(user.plainFont);
-
- Panel mainPanel = new Panel();
- mainPanel.setLayout(new BorderLayout());
- Panel centerPanel = new Panel();
- centerPanel.setLayout(new BorderLayout());
- Panel centerMainPanel = new Panel();
- centerMainPanel.setLayout(new GridLayout(2,1,1,1));
- Panel centerTopPanel = new JDPScrollPanel();
- Panel centerBottomPanel = new Panel();
- centerBottomPanel.setLayout(new BorderLayout());
- Panel leftPanel = new Panel();
- leftPanel.setLayout(new BorderLayout());
-
- //
- // Define parameters for JDPSearchResults
- //
- >005 String pselectFields = "<>"; String[] psdisplayFields = {<>};
- >006 pfromWhereClause = "<FROM JDPUser WHERE >";
-
- >007 psortChoice = new String[<5>];
- >008 psortChoice[<0>] = "<username>";
-
- >009 String[] psortChoiceText = {<"Sort by User Name","Sort by Card Number">};
- pdisplayChoice = psortChoice;
-
- >010 boolean pdisplayCount = <true>;
- >011 String pcountText = "<Total Entries:>";
-
- //
- // Create an instance of screen components
- //
- >012 <username> = new <TextField("",20)>;
-
- //
- // Initialise any choice components
- //
- loadChoices();
-
- //
- // Add components to the screen
- //
- >013 centerTopPanel.add("Left",new JDPWrapLabel(user,"<User Name:>",Color.<labelColor>));
- >014 centerTopPanel.add("Right",centerR<0>);
-
- centerMainPanel.add(centerTopPanel);
-
- //
- // Set screen component attributes
- //
- >039 <username>.setForeground(Color.<fcolor>);
- >040 <username>.setBackground(Color.<bcolor>);
-
- //
- // Create a new instance of a Grid
- //
- tableContents = new JDPTextGrid(user);
- centerBottomPanel.add("Center",tableContents);
- centerMainPanel.add(centerBottomPanel);
- //
- // Add buttons to the bottom of the panel
- //
- if (moduleParameter.compareTo("Inquiry") == 0) {
- >041 <username>.setEditable(false);
- String buttons[] = {""};
- centerBottomPanel.add("South",new JDPButtons(user, buttons, JDPButtons.HORIZONTAL));
- } else {
- >042 <username>.setEditable(<editable>);
- >015 String buttons[] = {<" Apply ","Reset","New","Copy","Remove">};
- centerBottomPanel.add("South",new JDPButtons(user, buttons, JDPButtons.HORIZONTAL));
- }
- mainPanel.add("Center",centerMainPanel);
-
- //
- // Define parameters for JDPWhereClause
- //
- >016 String[] pchooseFrom = new String[<7>];
- >017 pchooseFrom[<0>] = "<Account Name>";
-
- >018 String[] pactualchooseFrom = new String[<7>];
- >019 pactualchooseFrom[<0>] = "<username>";
-
- >020 String[][] pmatchUsing = new String[<7>][<7>];
- >021 pmatchUsing[<0>][<0>] = "<Begins with>";
-
- >022 String[][] pactualmatchUsing = new String[<7>][<7>];
- >023 pactualmatchUsing[<0>][<0>] = "< like >";
-
- >024 boolean[] constantIsString = new boolean[<7>];
- >025 constantIsString[<0>] = <true>;
-
- >026 int[] constantLength = new int[<7>];
- >027 constantLength[<0>] = <20>;
-
- //
- // Add JDPWhereClause search panel
- //
- if (pchooseFrom.length > 0) {
- >028 jdpWhereClause = new JDPWhereClause(user, "<UserBill>", true, "<pinitChoice>", pchooseFrom, pactualchooseFrom,
- pmatchUsing, pactualmatchUsing, null, null,
- constantLength, constantIsString);
- leftPanel.add("North",jdpWhereClause);
- }
- //
- // Add JDPSearchResults result list
- //
- if (psortChoice.length > 0) {
- >029 searchResults = new JDPSearchResults(user, <true>, jaggSQL, <false>, pselectFields, psdisplayFields, pfromWhereClause, psortChoiceText, psortChoice, pdisplayChoice, "<pinitChoice>", pdisplayCount, pcountText);
- leftPanel.add("Center",searchResults);
- mainPanel.add("West",leftPanel);
- }
-
- >030 add("Center",new JDPChiselFramePanel(user,"<User Billing Details>",mainPanel,"North"));
- if (psortChoice.length > 0) {
- newSearch();
- }
- // repaint the panel
- targetPanel.add("Center",this);
- targetPanel.paintAll(targetPanel.getGraphics());
- //
- // Add the handle to this panel to the global vector so other panels can
- // access this one
- //
- user.gParm.addElement(this);
- }
-
- //
- // Handle screen events
- //
- public boolean handleEvent(Event e) {
-
- switch (e.id) {
- case Event.ACTION_EVENT:
- if (e.target instanceof List) {
- if (e.target.equals(searchResults.resultList)) {
- loadData();
- return true;
- }
- }
- if (e.target instanceof JDPTreePicker) {
- if (e.target.equals(searchResults.tree)) {
- loadData();
- return true;
- }
- }
- if (e.target instanceof Button) {
- String choice = (String)e.arg;
- if (choice.trim().compareTo("Apply") == 0) {
- if (checkFields()) {
- checkRows();
- }
- return true;
- }
- if (choice.trim().compareTo("Reset") == 0) {
- if (insertRequested) {
- loadEmptyGrid();
- } else {
- loadGrid();
- }
- return true;
- }
- if (choice.trim().compareTo("Remove") == 0) {
- insertRequested = false;
- deleteRequested = true;
- checkRows();
- return true;
- }
- if (choice.trim().compareTo("Add") == 0) {
- if (!insertRequested) {
- insertRequested = true;
- loadEmptyGrid();
- }
- return true;
- }
- if (choice.trim().compareTo("Search") == 0) {
- insertRequested = false;
- newSearch();
- return true;
- }
- return true;
- }
- if (e.target instanceof Choice) {
- return true;
- }
- if (e.target instanceof TextField) {
- if ((jdpWhereClause != null) && (e.target.equals(jdpWhereClause.matchConstant))) {
- insertRequested = false;
- deleteRequested = false;
- newSearch();
- return true;
- }
- checkFields();
- return true;
- }
- return false;
-
- case Event.KEY_PRESS:
- if (e.key == '\t') {
- // handle tabbing between components
- if (e.modifiers != Event.SHIFT_MASK) {
- >031 if (e.target.equals(<username>)) { user.u.cursor(<username>); return true; }
- } else {
- >038 if (e.target.equals(<username>)) { user.u.cursor(<username>); return true; }
- }
- return true;
- }
- return false;
-
- case Event.WINDOW_EXPOSE:
- if (e.target instanceof JDPTabSelectTopPanel) {
- //
- // This is where you place code to get executed when this panel is
- // reactivated from the tab menu
- //
- return true;
- }
- return false;
-
- default:
- return false;
-
- }
- }
-
- //
- // Retrieve the handle to another panel so as to be able to interact with it
- //
- public void retrieveHandle() {
-
- for (int ix=0; ix<user.gParm.size(); ix++) {
- //
- // Activate the next four lines of code to retrieve the handle to another
- // Panel within your JDP system. Of course you should declare the variable
- // at the top of this source instead of within this method so you can
- // access it from all the methods within this class. You only need to
- // substitute DemoClass with the name ouf your class. You should call this
- // method from somewhere else in this class. To access a variable from
- // your resulting class use:
- // if (DemoClassHandle != null) mynewvar = demoClassHandle.variable;
- //
- // if (user.gParm.elementAt(ix) instanceof DemoClass19) {
- // DemoClass19 DemoClassHandle = (DemoClass19)user.gParm.elementAt(ix);
- // return;
- // }
- }
- }
-
- //
- // The search button was pressed so rerun the query with the new search criteria
- //
- public void newSearch() {
-
- String whereClause;
-
- whereClause = pfromWhereClause;
- if (jdpWhereClause != null) {
- whereClause = whereClause + " AND " + jdpWhereClause.whereClause;
- }
- searchResults.setFromWhereClause(whereClause);
- searchResults.clearList();
- searchResults.loadList();
- }
-
- //
- // Load the selected item
- //
- public void loadData() {
-
- StringTokenizer stok;
-
- int recCount = 0;
- Vector results = new Vector();
- String sep = jaggSQL.getSEP();
- int actualRows = 0;
- String row;
- String tempText;
-
- if ((itemIndex = searchResults.getSelectedIndex()) < 0) {
- clearFields();
- return;
- }
-
- >032 String SQL = <SELECT>;
-
- user.mainmsg.setStatusMsg("Accessing database...", 0);
- recCount = jaggSQL.execSQL(SQL, results);
-
- if(recCount == -1) {
- System.out.println("loadData SQL: "+SQL);
- user.mainmsg.setStatusMsg("SQL error. Contact the System Administrator", 20);
- return;
- }
- if(recCount >= 1) {
- row = (String)results.elementAt(0);
- if ((row != null) && (row.trim().compareTo("") != 0)) {
- stok = new StringTokenizer(row);
-
- >033 <username>.setText(stok.nextToken(sep).trim());
- }
- loadGrid();
- // if(recCount > 1) {
- // user.mainmsg.setStatusMsg("Multiple records found - first match only displayed.", 10);
- // } else {
- user.mainmsg.clearStatusMsg();
- // }
- } else {
- user.mainmsg.setStatusMsg("Requested entry does not exist.", 10);
- clearFields();
- }
-
- }
-
- //
- // Load the grid with the specified parameters and selected data
- //
- public void loadGrid() {
-
- StringTokenizer stok;
- int recCount = 0;
- Vector results = new Vector();
- String sep = jaggSQL.getSEP();
- int actualRows = 0;
- String row;
-
- Vector columns = new Vector();
- Vector indexes = new Vector();
-
- >100 String SQL = <SELECT>;
-
- user.mainmsg.setStatusMsg("Accessing database...", 0);
-
- recCount = jaggSQL.execSQL(SQL, results);
-
- if(recCount == -1) {
- user.mainmsg.setStatusMsg("SQL error. Contact the System Administrator", 20);
- System.out.println("loadGrid SQL: " + SQL);
- return;
- }
-
- //
- // Initialise result arrays
- //
- actualRows = jaggSQL.getRowCount();
- tableContents.currentText = new String[columnCount][actualRows];
- //
- // If we haven't already initialise the grid settings
- //
- if (columnCount != prevColumnCount) {
- prevColumnCount = columnCount;
- setGridSettings();
- }
- tableContents.cellChanged = null;
- tableContents.rowChanged = null;
- tableContents.columnSelected = null;
- >120 keyCount = <keycount>;
- rowKey = new String[actualRows][keyCount];
-
- //
- // Load key array and grid array
- //
- for (int ix=0; ix<actualRows; ix++) {
- row = (String)results.elementAt(ix);
- if ((row != null) && (row.trim().compareTo("") != 0)) {
- stok = new StringTokenizer(row);
- for (int iy=0; iy<keyCount; iy++) {
- rowKey[ix][iy] = stok.nextToken(sep).trim();
- }
- for (int iy=0; iy<columnCount; iy++) {
- tableContents.currentText[iy][ix] = stok.nextToken(sep).trim();
- }
- }
- }
-
- tableContents.newTable();
-
- //
- // Clear status message
- //
- user.mainmsg.clearStatusMsg();
- }
-
- //
- // Load the grid with the blank rows to allow data entry
- //
- public void loadEmptyGrid() {
-
- tableContents.currentText = new String[columnCount][50];
- tableContents.cellChanged = null;
- tableContents.rowChanged = null;
- tableContents.columnSelected = null;
- rowKey = new String[50][keyCount];
- tableContents.newTable();
- }
-
- //
- // Set up the parameters for this grid
- //
- public void setGridSettings() {
-
- tableContents.columnHeader = new String[columnCount];
- tableContents.columnHeaderStyle = new int[columnCount];
- tableContents.columnStyle = new int[columnCount];
- tableContents.columnHeaderColor = new Color[columnCount];
- tableContents.columnColor = new Color[columnCount];
- tableContents.columnBGColor = new Color[columnCount];
- tableContents.columnProtected = new boolean[columnCount];
- tableContents.columnWidth = new int[columnCount];
- tableContents.rightJustify = new boolean[columnCount];
- tableContents.rowHeader = null;
- tableContents.columnHeight = null;
- for (int ix=0; ix<columnCount; ix++) {
- tableContents.columnHeaderStyle[ix] = Font.BOLD;
- tableContents.columnStyle[ix] = Font.PLAIN;
- tableContents.columnHeaderColor[ix] = Color.black;
- tableContents.columnColor[ix] = Color.black;
- tableContents.columnBGColor[ix] = Color.white;
- tableContents.columnStyle[ix] = Font.PLAIN;
- }
- >101 tableContents.columnHeader[<ix>] = "<>";
- >102 tableContents.columnHeaderStyle[<ix>] = <>;
- >103 tableContents.columnStyle[<ix>] = <>;
- >104 tableContents.columnHeaderColor[<ix>] = user.u._cvtcolor("<>");
- >105 tableContents.columnColor[<ix>] = user.u._cvtcolor("<>");
- >106 tableContents.columnBGColor[<ix>] = user.u._cvtcolor("<>");
- >107 tableContents.columnProtected[<ix>] = <>;
- >108 tableContents.columnWidth[<ix>] = <>;
- >109 tableContents.rightJustify[<ix>] = <>;
-
- }
-
- //
- // The check each rows that has changed and issue an update to the database
- //
- public void checkRows() {
-
- int changedCount = 0;
- int thisCount = 1;
-
- if (!deleteRequested) {
- for (int ix=0; ix<tableContents.rowChanged.length; ix++) {
- if (tableContents.rowChanged[ix]) {
- changedCount++;
- }
- }
- for (int ix=0; ix<tableContents.rowChanged.length; ix++) {
- if (tableContents.rowChanged[ix]) {
- if (insertRequested) {
- user.mainmsg.setStatusMsg("Inserting row " + Integer.toString(thisCount++) + " of " + Integer.toString(changedCount) + "...", 0);
- } else {
- user.mainmsg.setStatusMsg("Updating row " + Integer.toString(thisCount++) + " of " + Integer.toString(changedCount) + "...", 0);
- }
- saveData(ix);
- tableContents.rowChanged[ix] = false;
- }
- }
- if ((insertRequested) && (changedCount > 0)) {
- loadEmptyGrid();
- }
- } else {
- for (int ix=0; ix<tableContents.rowSelected.length; ix++) {
- if (tableContents.rowSelected[ix]) {
- changedCount++;
- }
- }
- if (changedCount == 0) {
- user.mainmsg.setStatusMsg("Select the row you wish to remove by clicking on the row number button.", 7);
- } else {
- for (int ix=0; ix<tableContents.rowSelected.length; ix++) {
- if (tableContents.rowSelected[ix]) {
- user.mainmsg.setStatusMsg("Deleting row " + Integer.toString(thisCount++) + " of " + Integer.toString(changedCount) + "...", 0);
- saveData(ix);
- tableContents.rowChanged[ix] = false;
- }
- }
- newSearch();
- }
- }
- }
-
- //
- // Save the selected item
- //
- public boolean saveData(int tableRow) {
-
- int recCount = 0;
- Vector results = new Vector();
- String sep = jaggSQL.getSEP();
- String SQL = "";
-
- if (insertRequested) {
- >121 SQL = <INSERT INTO >;
- } else {
- if (deleteRequested) {
- >122 SQL = <DELETE FROM >;
- } else {
- >123 SQL = <UPDATE >;
- }
- }
-
- recCount = jaggSQL.execSQL(SQL, results);
-
- if (user.DEBUG) System.out.println("saveData CNT: "+Integer.toString(recCount));
-
- if(recCount == -1) {
- System.out.println("saveData SQL: "+SQL);
- user.mainmsg.setStatusMsg("SQL error. Contact the System Administrator.", 10);
- return false;
- }
- if(recCount == 1) {
- if (insertRequested) {
- user.mainmsg.setStatusMsg("Record successfully added.",3);
- } else
- if (deleteRequested) {
- user.mainmsg.setStatusMsg("Record successfully removed.",3);
- } else {
- user.mainmsg.setStatusMsg("Record successfully updated.",3);
- }
- } else {
- user.mainmsg.setStatusMsg("SQL failed. Contact the System Administrator.", 10);
- }
- deleteRequested = false;
- return true;
-
- }
-
- //
- // Clear the screen fields for a new option
- //
- public void clearFields() {
-
- >037 <username>.setText("");
- loadEmptyGrid();
-
- }
-
- //
- // Load all of the Screen Choices
- //
- public void loadChoices() {
- >043
- >044 new JDPLoadChoice(user,jaggSQL,<choicename>,"<choicecolumnname>","<actualcolumnname>","<tablename>","<whereclause>",value<columnname>);
- }
-
- //
- // Perform component validations
- //
- public boolean checkFields() {
-
- >045 if (!user.u.<isnumeric>(<field>,user.mainmsg)) return false;
- return true;
-
- }
-
-
- }
-